from google.appengine.ext import db
from google.appengine.api import users


class Topic(db.Model):
    content = db.StringProperty(multiline=True)
    score = db.IntegerProperty()

class TopicDao:
    topicsList = []
    
    def __init__(self):             # Assign method name
        topic_query = Topic.all().order('-score')
        self.topicsList = topic_query.fetch(1000)
    
    def loadAll(self):
        return self.topicsList
    
    def getTopic(self, content):
        topic_query = Topic.gql("WHERE content = :1", content)
        topic = topic_query.fetch(1)
        return topic

    def getTopicWithKey(self, keyString):
        topic_query = Topic.gql("WHERE __key__ = :1", db.Key(keyString))
        topic = topic_query.fetch(1)
        return topic
    